import React, { useState }  from 'react';
import './index.less';
import api from '../../axios'
import { Button, Image,
  Descriptions,
  message,
  Switch,
  Input,
   } from 'antd';



class index extends React.Component {
    constructor(props) {
        super(props);
        this.state = { 
            visible: false,
            loading: true,
            fileloading: false,
            imageUrl: '',
            initialValues: {},
            data: '0',
            value: 0,
            editModalVis: false,
            phone: '',
        };
    }

    confirm = (e) => {
        message.success('操作成功');
    }


    componentDidMount(){
        this.getData()
    }

    onChange = (checked) => {
        console.log(`switch to ${checked}`);
        this.changeState()
    };

    changeState = async () => {
        let res = await api.ajax({
            method: 'post',
            url: `/config/imgswitch`,
            data: {
                status: this.state.data == '1' ? 0 : 1
            }
        });

        this.getData()

    }
    
    getData = async () => {
      let res = await api.ajax({
          method: 'get',
          url: `/config/customer`,
      });

      this.setState({
          value: res.data.value,
      })
    }

    onOk = () => {

    }
    
    render() {
      const { value, phone } = this.state

      const save = async () => {
        let res = await api.ajax({
            method: 'post',
            url: `/config/customer`,
            data: {
                value: value
            }
        });

        message.success('保存成功');

        this.getData()
      }

        return (
           <>
             <div className='wapper'>
                <div>
                  <Descriptions title="客服设置">
                    <Descriptions.Item label="客服电话">
                        <Input value={value} placeholder={'请输入客服电话'} className='input' onChange={(e) => {
                            this.setState({
                                value: e.target.value
                            })
                        }}/>
                        <Button type="primary" className='save' onClick={() => save()}>保存</Button>
                    </Descriptions.Item>
                  </Descriptions>
                </div>
             </div>
           </>
        );
    }
}

export default index;